<?php

namespace App\Http\Controllers\CRM;

use App\Helper\ApiResponseHelper;
use App\Http\Controllers\Controller;
use App\Models\Store;
use Illuminate\Http\Request;

class StatisticsController extends Controller
{
    /**
     * 门店时间段统计
     * @param Store $store
     */
    public function store(Store $store, Request $request)
    {
        $date = $request->date;
        if (empty($date))
            return ApiResponseHelper::json([], 400, '日期不能为空');

        return ApiResponseHelper::json([
            'store' => $store,
            'date' => $date,
            'data' => [
                //营业额
                'turnover_money' => 12023,
                //客单数
                'customer_order' => 234,
                //退款额
                'refund_money' => 0,
                //新客人数
                'new_customer' => 12,
                //营业数据
                'turnover' => [
                    //实际收入
                    'actual_income' => 12023,
                    //平台应收
                    'platform_receivable' => 2323,
                    //挂账变化
                    'credit_change' => 0,
                    //商品实收
                    'goods_actual_income' => 2330,
                    //台费收入
                    'table_fee_income' => 2434,
                    //助教陪打
                    'assistant_income' => 8000,
                    //助教激励
                    'assistant_incentive' => 0,
                    //预付消费
                    'prepaid_consumption' => 0,
                    //会员卡消费
                    'member_card_consumption' => 4442,
                ],
                //流水统计
                'flow' => [
                    //商品流水
                    'goods_flow' => 4664,
                    //台费流水
                    'table_fee_flow' => 2434,
                    //助教流水
                    'assistant_flow' => 8000,
                    //助教激励
                    'assistant_incentive' => 0,
                ],
                //共同包含项
                'common' => [
                    //自营团购券
                    'self_group_coupon' => 0,
                    //预存收入
                    'prepaid_income' => 0,
                    //会员卡充值
                    'member_card_recharge' => 0,
                    //服务加收
                    'service_charge' => 0,
                    //取整收入
                    'rounding_income' => 0,
                ],
                //实时指标
                'real_time' => [
                    //开台率
                    'open_rate' => 21,
                    //台桌开台数
                    'table_open' => 23,
                    //真实台桌总数
                    'real_table' => 56,
                    //真实台桌开台数
                    'real_table_open' => 21,
                    //虚拟台桌开台数
                    'virtual_table_open' => 0,
                    //台桌空闲数
                    'table_free' => 20,
                    //助教陪打率
                    'assistant_rate' => 10,
                    //助教上钟数
                    'assistant_clock' => 1,
                    //助教空闲数
                    'assistant_free' => 10,
                ],
                //基础概况
                'base' => [
                    //营业额
                    'turnover' => 23220,
                    //线上营业额
                    'online_turnover' => 23220,
                    //线下营业额
                    'offline_turnover' => 0,
                    //总收入
                    'total_income' => 23220,
                    //利润
                    'profit' => 23220,
                    //聚合支付金额
                    'aggregate_payment' => 23220,
                    //台桌空闲数
                    'table_free' => 23,
                    //线上客单数
                    'online_customer_order' => 0,
                    //线下客单数
                    'offline_customer_order' => 0,
                ],
                //台桌消费金额占比
                'table' => [
                    ['区域A' => 100],
                    ['区域B' => 200],
                    ['区域C' => 300],
                    ['区域D' => 400],
                ],
                //营业额相关时间段
                'turnover_time' => [
                    '00:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                    '04:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                    '08:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                    '12:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                    '16:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                    '20:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                    '24:00' => [
                        //营业额
                        ['turnover' => 500],
                        //会员充值金额
                        ['member_recharge' => 400],
                        //商品销售金额
                        ['goods_sales' => 100],
                        //台桌收入
                        ['table_income' => 0],
                        //助教收入
                        ['assistant_income' => 0],
                    ],
                ],
            ]
        ]);
    }
}
